from configparser import ConfigParser
from fabric import Connection

config = ConfigParser()
config.read('../config.ini', encoding='utf-8')


class ConnectionPool:
    Pool = {}
    user = config['base']['user']
    password = config['base']['password']
    ip_hosts = config['base']['ip_hosts'].split(',')
    for item in ip_hosts:
        item = item.split(":")
        Pool[item[1]] = Connection(item[0], user, connect_kwargs={'password': password},
                                   connect_timeout=5)

    @classmethod
    def get_conn(cls, host):
        return cls.Pool[host]
